package com.xiaocg.base.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author xiaocg
 */
public class AqsDemo {
    public static void main(String[] args) throws Exception{
        BlockingQueue<String> queue = new ArrayBlockingQueue<>(2);
        new Thread(()->{
            try {
                for (int i = 0; i < 5; i++) {
                    queue.put(""+(i+1));
                    System.out.println("放完了:"+(i+1));
                }
            }catch (Exception e){

            }

        },"write").start();

        new Thread(()->{
            try {
                for (int i = 0; i < 5; i++) {
                    System.out.println("取完了:"+queue.take());
                }
            }catch (Exception e){

            }

        },"read").start();

    }
}
